const { formatDate } = require("../utils/transform_tool");
const { BaseCommand } = require("./base");

class DateCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        let date = data?.date || new Date();
        if (typeof date === "string") {
            date = new Date(date);
        }
        if (data) {
            if (data.offset) {
                date.setTime(date.getTime() + data.offset);
            }
            if (data.format) {
                date = formatDate(date, data.format);
            }
        }
        return date;
    }
}

module.exports = {
    DateCommand,
};
